package smlab.utils
{
	import flash.display.InteractiveObject;
	import flash.events.ContextMenuEvent;
	import flash.ui.ContextMenu;
	import flash.ui.ContextMenuItem;

	/**
	 * 鼠标右键菜单管理类
	 * @author Simon
	 * 
	 */
	public class MouseMenu
	{
		public function MouseMenu()
		{
		}
		
		/**
		 * 
		 * @param menuContainerArr	
		 * 							
		 * 
		 */
		/**
		 * 为显示对象添加右键菜单
		 * @param menuContainer		想要添加右键菜单的显示对象
		 * @param menuTxtArr		各个菜单的文本
		 * @param clickFunArr		各个菜单点击后执行的方法
		 * 
		 */
		public static function addMenu(menuContainer:InteractiveObject,menuTxtArr:Array,clickFunArr:Array):void
		{
			var m:ContextMenu = new ContextMenu();
			m.hideBuiltInItems();
			
			for(var i:int=0;i<menuTxtArr.length;i++){
				var str:String=menuTxtArr[i];
				
				if(str){
					var item:ContextMenuItem=new ContextMenuItem(str);
					var f:Function=clickFunArr[i];
					
					if(f!=null){
						item.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, f);
					}
					
					m.customItems.push(item);
				}
			}
			
			menuContainer.contextMenu=m;
		}
		
		public static function removeMenu(menuContainer:InteractiveObject):void
		{
			var m:ContextMenu = new ContextMenu();
			m.hideBuiltInItems();
			menuContainer.contextMenu=m;
		}
	}
}